package com.neusoft.neuiotms.dcom.converter.malfunction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.malfunction.MalfunctionSecondLeaderDTO;
import com.neusoft.neuiotms.dcom.model.malfunction.MalfunctionSecondLeader;
import com.neusoft.neuiotms.dcom.repository.malfunction.MalfunctionSecondLeaderRepository;

@Component
public class MalfunctionSecondLeaderConverter
        extends AbstractConverter<MalfunctionSecondLeader, MalfunctionSecondLeaderDTO> {

    @Autowired
    private MalfunctionSecondLeaderRepository secondLeaderRepository;

    @Override
    public MalfunctionSecondLeader toModel(final MalfunctionSecondLeaderDTO dto) {

        MalfunctionSecondLeader model;
        if (dto.isNew()) {
            model = new MalfunctionSecondLeader();
        } else {
            model = this.secondLeaderRepository.getOne(dto.getId());
        }

        model.setTaskId(dto.getTaskId());
        model.setWorkNum(dto.getWorkNum());
        model.setOperatorCode(dto.getOperatorCode());
        model.setOperatorName(dto.getOperatorName());
        model.setSecondOperatorCode(dto.getSecondOperatorCode());
        model.setSecondOperatorName(dto.getSecondOperatorName());

        return model;
    }

    @Override
    public MalfunctionSecondLeaderDTO toDTO(final MalfunctionSecondLeader model, final boolean forListView) {

        final MalfunctionSecondLeaderDTO dto = new MalfunctionSecondLeaderDTO();
        dto.setId(model.getId());
        dto.setTaskId(model.getTaskId());
        dto.setWorkNum(model.getWorkNum());
        dto.setOperatorCode(model.getOperatorCode());
        dto.setOperatorName(model.getOperatorName());
        dto.setSecondOperatorName(model.getSecondOperatorName());
        return dto;
    }

}
